/**
 * 应用相关
 */
package com.scpii.universal.service.mobile;

import java.net.URLEncoder;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.scpii.api.common.auth.token.TokenService;
import com.scpii.api.domain.auth.UsersInfoDetails;
import com.scpii.universal.hibernate.entity.AppDetailPageTab;
import com.scpii.universal.hibernate.entity.AppIconTab;
import com.scpii.universal.hibernate.entity.AppPageTab;
import com.scpii.universal.hibernate.entity.AppPageViewTab;
import com.scpii.universal.hibernate.entity.AppTab;
import com.scpii.universal.hibernate.entity.AppUpdateTab;
import com.scpii.universal.hibernate.entity.AppViewCatelogRalationTab;
import com.scpii.universal.hibernate.entity.AttributeTab;
import com.scpii.universal.hibernate.entity.CatelogTab;
import com.scpii.universal.hibernate.entity.ContentTab;
import com.scpii.universal.hibernate.entity.MoreContentTab;
import com.scpii.universal.hibernate.entity.SortCondition;
import com.scpii.universal.hibernate.entity.ViewContentAttributeTab;
import com.scpii.universal.pb.PbUniversal.PBRESULT;
import com.scpii.universal.pb.PbUniversal.PbAppCS;
import com.scpii.universal.pb.PbUniversal.PbAppPageCatelogCS;
import com.scpii.universal.pb.PbUniversal.PbAppPageCatelogSC;
import com.scpii.universal.pb.PbUniversal.PbAppPageContentCS;
import com.scpii.universal.pb.PbUniversal.PbAppPageContentSC;
import com.scpii.universal.pb.PbUniversal.PbAppSC;
import com.scpii.universal.pb.PbUniversal.PbAppUpdateCS;
import com.scpii.universal.pb.PbUniversal.PbAppUpdateSC;
import com.scpii.universal.pb.PbUniversalBasic.PbApp;
import com.scpii.universal.pb.PbUniversalBasic.PbApp.PbAppImgUrls;
import com.scpii.universal.pb.PbUniversalBasic.PbAppContentPage;
import com.scpii.universal.pb.PbUniversalBasic.PbAppPage;
import com.scpii.universal.pb.PbUniversalBasic.PbAppPageContent;
import com.scpii.universal.pb.PbUniversalBasic.PbAppPageContentList;
import com.scpii.universal.pb.PbUniversalBasic.PbAppPageContentView;
import com.scpii.universal.pb.PbUniversalBasic.PbAppUpdate;
import com.scpii.universal.pb.PbUniversalBasic.PbContentAttributeValue;
import com.scpii.universal.pb.PbUniversalBasic.PbContentAttributeValueList;
import com.scpii.universal.pb.PbUniversalBasic.PbMoreContent;
import com.scpii.universal.pb.PbUniversalBasic.PbMoreContentList;
import com.scpii.universal.pb.PbUniversalBasic.PbPageView;
import com.scpii.universal.pb.PbUniversalBasic.PbPageViewCatelog;
import com.scpii.universal.pb.PbUniversalBasic.PbPageViewCatelogList;
import com.scpii.universal.pb.PbUniversalBasic.PbPageViewList;
import com.scpii.universal.pns.hibernate.entity.Field;
import com.scpii.universal.pns.hibernate.entity.FieldValues;
import com.scpii.universal.pns.hibernate.entity.Users;
import com.scpii.universal.pns.service.AddressService;
import com.scpii.universal.pns.service.FieldService;
import com.scpii.universal.pns.service.FieldValuesService;
import com.scpii.universal.pns.service.UserPointRanksService;
import com.scpii.universal.pns.service.UsersService;
import com.scpii.universal.service.AppDetailPageTabService;
import com.scpii.universal.service.AppIconTabService;
import com.scpii.universal.service.AppPageTabService;
import com.scpii.universal.service.AppPageViewTabService;
import com.scpii.universal.service.AppTabService;
import com.scpii.universal.service.AppUpdateTabService;
import com.scpii.universal.service.AppViewCatelogRalationTabService;
import com.scpii.universal.service.AppViewContentRelationTabService;
import com.scpii.universal.service.AttributeTabService;
import com.scpii.universal.service.AttributeValueTabService;
import com.scpii.universal.service.BindContentAttributeTabService;
import com.scpii.universal.service.CatelogTabService;
import com.scpii.universal.service.ContentTabService;
import com.scpii.universal.service.MoreContentTabService;
import com.scpii.universal.service.ViewContentAttributeTabService;
import com.scpii.universal.util.Const;

/**
 * UniversalApi
 * 
 * @author 甘建新 2012-7-11下午11:01:37
 */
public class MobileAppService {
	/**
	 * private AppTabService appTabService = new AppTabService(); private
	 * AppUpdateTabService appUpdateTabService = new AppUpdateTabService();
	 * private AppPageTabService appPageTabService = new AppPageTabService();
	 * private PageTitleTabService pageTitleTabService = new
	 * PageTitleTabService(); private PageAttributeTabService
	 * pageAttributeTabService = new PageAttributeTabService(); private
	 * ModuleStyleTabService moduleStyleTabService = new
	 * ModuleStyleTabService(); private AppStyleTabService appStyleTabService =
	 * new AppStyleTabService(); private CatelogTabService catelogTabService =
	 * new CatelogTabService(); private AttributeTabService attributeTabService
	 * = new AttributeTabService(); private AppPageViewTabService
	 * appPageViewTabService = new AppPageViewTabService(); private
	 * AppViewCatelogRalationTabService appViewCatelogRalationTabService = new
	 * AppViewCatelogRalationTabService(); private AppIconTabService
	 * appIconTabService = new AppIconTabService(); private ContentTabService
	 * contentTabService = new ContentTabService(); private
	 * ViewContentAttributeTabService viewContentAttributeTabService = new
	 * ViewContentAttributeTabService(); private AttributeValueTabService
	 * attributeValueTabService = new AttributeValueTabService(); private
	 * AppDetailPageTabService appDetailPageTabService = new
	 * AppDetailPageTabService();
	 **/
	private AppTabService appTabService;
	private AppUpdateTabService appUpdateTabService;
	private AppPageTabService appPageTabService;
	private CatelogTabService catelogTabService;
	private AttributeTabService attributeTabService;
	private AppPageViewTabService appPageViewTabService;
	private AppViewCatelogRalationTabService appViewCatelogRalationTabService;
	private AppIconTabService appIconTabService;
	private ContentTabService contentTabService;
	private ViewContentAttributeTabService viewContentAttributeTabService;
	private AttributeValueTabService attributeValueTabService;
	private AppDetailPageTabService appDetailPageTabService;
	private AppViewContentRelationTabService appViewContentRelationTabService;
	private BindContentAttributeTabService bindContentAttributeTabService;
	private MobilePageService mobilePageService;
	private TokenService tokenService;
	private MoreContentTabService moreContentTabService;
	private UsersService usersService;
	private FieldService fieldService;
	private FieldValuesService fieldValuesService;
	private AddressService addressService;
	private UserPointRanksService userPointRanksService;

	private Logger log = Logger.getLogger(MobileAppService.class);

	private String LOG_METHOD_NAME = "";

	/**
	 * 获得应用信息 GET_APP
	 * 
	 * @param appCs
	 * @return
	 * @author 甘建新 2012-7-11下午11:08:29
	 */
	public byte[] getApp(byte[] bytes) {
		LOG_METHOD_NAME = "getApp";

		PbAppSC.Builder pbAppSCBuilder = PbAppSC.newBuilder();
		PbApp.Builder pbAppBuilder = PbApp.newBuilder();
		if (bytes != null) {
			try {
				// 转换客户端传递过来的参数
				PbAppCS pbAppCS = PbAppCS.parseFrom(bytes);
				int appId = pbAppCS.getIntAppId();
				log.info(LOG_METHOD_NAME + "【appId:" + appId + "】");
				// 获得应用信息
				AppTab appTab = appTabService.get(appId);
				if (appTab != null) {
					// 设置应用基础信息
					pbAppBuilder.setDatAppEndDatetime(appTab
							.getDatAppServEndtime());
					pbAppBuilder.setDatAppStartDatetime(appTab
							.getDatAppServStarttime());
					pbAppBuilder.setDobAppMoney(appTab.getDobAppMoney());
					pbAppBuilder.setIntAppId(appTab.getIntAppId());
					pbAppBuilder.setIntEnterpId(appTab.getIntEnterpId());
					pbAppBuilder.setVarAppName(appTab.getVarAppName());
					pbAppBuilder.setVarAppDescrip(appTab.getVarAppDescript());

					// 设置应用中包含的图片列表
					PbAppImgUrls.Builder pbAppImgUrlBuilder = PbAppImgUrls
							.newBuilder();
					pbAppBuilder.addPbAppImgUrlsList(pbAppImgUrlBuilder);

					// 设置获取数据状态
					pbAppSCBuilder.setPbApp(pbAppBuilder);
					pbAppSCBuilder.setExeResult(PBRESULT.SUCCESS);
				} else {
					log.info(LOG_METHOD_NAME + Const.LOG_DATA_NULL);
					pbAppSCBuilder.setExeResult(PBRESULT.NULL);
				}
			} catch (Exception e) {
				log.error(LOG_METHOD_NAME + Const.LOG_DATA_EXCEPTION, e);
				e.printStackTrace();
				pbAppSCBuilder.setExeResult(PBRESULT.EXCEPTION);
			}
		} else {
			log.info(LOG_METHOD_NAME + Const.LOG_BYTE_NULL);
			pbAppSCBuilder.setExeResult(PBRESULT.FAILED);
		}
		return pbAppSCBuilder.build().toByteArray();
	}

	/**
	 * 获得应用版本信息
	 * 
	 * @param appUpdateCS
	 * @return
	 * @author 甘建新 2012-7-11下午11:09:52
	 */
	public byte[] getAppUpdate(byte[] bytes) {
		LOG_METHOD_NAME = "getAppUpdate";
		PbAppUpdateSC.Builder pbAppUpdateSCBuilder = PbAppUpdateSC.newBuilder();
		PbAppUpdate.Builder pbAppUpdateBuilder = PbAppUpdate.newBuilder();
		if (bytes != null) {
			try {
				// 转化参数
				PbAppUpdateCS pbAppUpdateCS = PbAppUpdateCS.parseFrom(bytes);
				int appUpdateId = pbAppUpdateCS.getIntAppUpdateId();
				int appId = pbAppUpdateCS.getIntAppId();
				int OSTYPE = pbAppUpdateCS.getOsType().getNumber();
				double dobAppUpdateVersion = pbAppUpdateCS
						.getDobAppUpdateVersion();
				log.info(LOG_METHOD_NAME + "【appUpdateId:" + appUpdateId
						+ ",appId:" + appId + ",OSTYPE:" + OSTYPE
						+ ",dobAppUpdateVersion:" + dobAppUpdateVersion + "】");

				AppUpdateTab needUpdateApp = appUpdateTabService
						.getNeed2UpdateApp(appId, OSTYPE, dobAppUpdateVersion);
				// loading更新
				AppUpdateTab maxVersionApp = appUpdateTabService
						.getMaxVersionApp(appId, OSTYPE);
				if (maxVersionApp.getIntLoadingIconId() != null) {
					AppIconTab loading = appIconTabService.get(maxVersionApp
							.getIntLoadingIconId());
					if (!StringUtils.isBlank(loading.getVarIconUrl())
							&& loading.getIntIconType() == 9) {
						pbAppUpdateBuilder.setIntLoadingState(1);
						pbAppUpdateBuilder.setVarLoadingUrl(loading
								.getVarIconUrl());
					}
				} else {
					pbAppUpdateBuilder.setIntLoadingState(0);
				}
				if (needUpdateApp != null) {
					// 版本更新
					AppUpdateTab appUpdate = appUpdateTabService.getUpdateApp(
							appId, OSTYPE, dobAppUpdateVersion, needUpdateApp);
					String appDownloadUrl = "";
					// 根据系统类型获取各自的下载地址
					if (OSTYPE == Const.OS_ANDROID) {
						appDownloadUrl = appUpdate.getVarAppDownloadUrl();
					} else if (OSTYPE == Const.OS_IOS) {
						appDownloadUrl = appUpdate.getVarIosInstallUrl();
					}
					// 去空，构造应用下载地址
					if (appDownloadUrl != null
							&& appDownloadUrl.trim().length() > 0) {
						appDownloadUrl = Const.HOST_APP_DOWNLOAD_PATH
								+ "?ostype=" + OSTYPE + "&appurl="
								+ URLEncoder.encode(appDownloadUrl, "utf-8");
					} else {
						appDownloadUrl = "";
					}

					pbAppUpdateBuilder.setVarAppDownloadUrl(appDownloadUrl);
					pbAppUpdateBuilder.setVarAppOSType(appUpdate
							.getIntAppOsType() + "");
					pbAppUpdateBuilder.setVarAppSign(appUpdate.getVarAppSign());
					pbAppUpdateBuilder.setDobAppVersion(appUpdate
							.getDobAppVersion());
					pbAppUpdateBuilder.setIntAppDownloadCount(appUpdate
							.getIntAppDownCount() + "");
					pbAppUpdateBuilder.setIntAppUpdateId(appUpdate
							.getIntAppUpdateId());
					pbAppUpdateBuilder.setIntAppId(appUpdate.getIntAppId());
					pbAppUpdateBuilder.setIntUpdateState(appUpdate
							.getIntState());

					String appUpdateMsg = "";
					int appState = pbAppUpdateBuilder.getIntUpdateState();
					if (appState == Const.APP_NOT_UPDATE) {
						appUpdateMsg = Const.MSG_APP_NOT_UPDATE;
					} else if (appState == Const.APP_MUST_UPDATE) {
						appUpdateMsg = Const.MSG_APP_MUST_UPDATE;
					} else if (appState == Const.APP_CAN_UPDATE) {
						appUpdateMsg = Const.MSG_APP_CAN_UPDATE;
					}
					pbAppUpdateSCBuilder.setVarAppUpdateMsg(appUpdateMsg);
				}
				pbAppUpdateSCBuilder.setPbAppUpdate(pbAppUpdateBuilder);
				pbAppUpdateSCBuilder.setExeResult(PBRESULT.SUCCESS);
				log.info(LOG_METHOD_NAME + Const.LOG_DATA_SUCCESS);
			} catch (Exception e) {
				log.error(LOG_METHOD_NAME + Const.LOG_DATA_EXCEPTION, e);
				e.printStackTrace();
				pbAppUpdateSCBuilder.setExeResult(PBRESULT.EXCEPTION);
			}
		} else {
			log.info(LOG_METHOD_NAME + Const.LOG_BYTE_NULL);
			pbAppUpdateSCBuilder.setExeResult(PBRESULT.FAILED);
		}
		return pbAppUpdateSCBuilder.build().toByteArray();
	}

	/**
	 * 获得页面展示信息
	 * 
	 * @param bytes
	 * @return
	 * @author 甘建新 2012-7-24上午11:14:50
	 */
	public byte[] getAppPage(byte[] bytes) {
		LOG_METHOD_NAME = "getAppPage";
		PbAppPageCatelogSC.Builder pbAppPageSCB = PbAppPageCatelogSC
				.newBuilder();
		PbAppPage.Builder pbAppPageB = PbAppPage.newBuilder();
		if (bytes != null) {
			try {
				PbAppPageCatelogCS pbAppPageCSB = PbAppPageCatelogCS
						.parseFrom(bytes);
				int appId = pbAppPageCSB.getIntAppId();
				int pageId = pbAppPageCSB.getIntPageId();
				String accessTokenValue = pbAppPageCSB.getAccessTokenValue();

				log.info(LOG_METHOD_NAME + "【appId:" + appId + ",pageId:"
						+ pageId + "token:" + accessTokenValue + "】");
				// 校验是否登录 start
				boolean isLogin = false;
				UsersInfoDetails userInfo = tokenService
						.loadUsersInfoDetails(accessTokenValue);
				Users user = null;
				long userId = 0;
				if (userInfo != null && !"ANON".equals(userInfo.getUserType())) {
					isLogin = true;
					userId = userInfo.getId();
					user = usersService.get(userId);
				}
				// 校验是否登录 end
				AppPageTab appPage = appPageTabService
						.getPagesListByPageIdAppId(appId, pageId);
				List<AppPageViewTab> appViewList = appPageViewTabService
						.getViewListByPageId(pageId);

				if (appPage != null
						&& (appViewList != null && appViewList.size() > 0)) {
					// 设置页面基本的信息
					pbAppPageB.setIntAppId(appPage.getIntAppId());
					pbAppPageB.setIntPageId(appPage.getIntResourceId());
					pbAppPageB.setVarPageName(appPage.getVarTitleName());
					pbAppPageB.setIntEnterpId(appPage.getIntEnterpId());

					// 定义页面标题信息
					String varTitleName = appPage.getVarTitleName();
					Integer titleIconId = appPage.getIntTitleIconId();
					AppIconTab titleIcon = null;
					if (titleIconId != null && titleIconId != 0) {
						titleIcon = appIconTabService.get(appPage
								.getIntTitleIconId());
					}
					String titleIconUrl = "";
					if (titleIcon != null) {
						titleIconUrl = titleIcon.getVarIconUrl();
					}
					String varTitleIconImg = (titleIconUrl);

					if (varTitleName == null || varTitleName.trim().equals("")) {
						varTitleName = "";
					}
					if (varTitleIconImg == null
							|| varTitleIconImg.trim().equals("")) {
						varTitleIconImg = "";
					}
					pbAppPageB.setVarTitleName(varTitleName);
					pbAppPageB.setVarTitleIconImg(varTitleIconImg);
					// pbAppPageB.setVarTitleBackgImg(varTitleBackgImg);

					// 定义页面中包含的视图列表
					PbPageViewList.Builder pbPageViewList = PbPageViewList
							.newBuilder();
					// 设置页面包含的VIEW信息
					if (checkIfViewNeedLogin(appViewList) && !isLogin) {
						log.info("appId:" + userInfo.getAppId() + "userName:"
								+ userInfo.getUserName() + "userId:"
								+ userInfo.getId() + "未登录");
						pbAppPageSCB.setExeResult(PBRESULT.NEEDLOGIN);
						PbAppPageCatelogSC pbAppPageCatelogSC = pbAppPageSCB
								.build();
						return pbAppPageCatelogSC.toByteArray();
					}
					for (AppPageViewTab pageView : appViewList) {
						PbPageView.Builder pbPageViewB = PbPageView
								.newBuilder();
						pbPageViewB.setIntModuleStyleId(pageView
								.getIntModuleStyleId());
						pbPageViewB.setIntResourceId(pageView
								.getIntResourceId());
						pbPageViewB.setIntViewId(pageView.getIntViewId());
						pbPageViewB.setIntViewOrder(pageView.getIntViewOrder());
						pbPageViewB.setVarViewName(pageView.getVarViewName());
						pbPageViewB.setVarViewConfig(pageView
								.getVarViewConfig() == null ? "" : pageView
								.getVarViewConfig());

						int intViewDataType = pageView
								.getIntViewBingdDataType();
						pbPageViewB.setIntDataType(intViewDataType);
						int pageCount = 0;
						if (intViewDataType == Const.VIEW_BIND_CATELOG) {// 视图绑定内容为分类
							// 设置View中显示的数据列表
							PbPageViewCatelogList.Builder pbViewCateListB = PbPageViewCatelogList
									.newBuilder();
							// 设置绑定的分类的页数
							pageCount = appViewCatelogRalationTabService
									.returnPageCountByViewId(pageView
											.getIntViewId());
							pbPageViewB.setIntPageNum(pageCount);
							// 查询View和分类之间的关系信息
							List<AppViewCatelogRalationTab> appViewCateRTabList = appViewCatelogRalationTabService
									.getViewCateListByViewId(
											pageView.getIntViewId(), 1);
							if (appViewCateRTabList != null
									&& appViewCateRTabList.size() > 0) {
								for (AppViewCatelogRalationTab appViewCate : appViewCateRTabList) {
									PbPageViewCatelog.Builder pbPageViewCateB = PbPageViewCatelog
											.newBuilder();
									pbPageViewCateB.setIntCateId(appViewCate
											.getIntCateId());
									pbPageViewCateB
											.setIntResourceId(appViewCate
													.getIntResourceId());
									pbPageViewCateB
											.setIntViewCateId(appViewCate
													.getIntViewCateId());
									pbPageViewCateB.setIntViewId(appViewCate
											.getIntViewId());
									pbPageViewCateB
											.setIntNextPageType(appViewCate
													.getIntContentType());

									// 获得分类对象信息
									CatelogTab catelogTab = catelogTabService
											.get(appViewCate.getIntCateId());
									if (catelogTab != null) {
										if (catelogTab.getIntPrivilege() != CatelogTab.PUBLIC_PRIVILEGE
												&& !isLogin) {
											// 非公共权限，需登录
											log.info("appId:"
													+ userInfo.getAppId()
													+ "userName:"
													+ userInfo.getUserName()
													+ "userId:"
													+ userInfo.getId() + "未登录");
											pbAppPageSCB
													.setExeResult(PBRESULT.NEEDLOGIN);
											PbAppPageCatelogSC pbAppPageCatelogSC = pbAppPageSCB
													.build();
											return pbAppPageCatelogSC
													.toByteArray();
										}
										pbPageViewCateB
												.setVarCateName(catelogTab
														.getVarCateName());
										pbPageViewCateB
												.setVarCateImgUrl(catelogTab
														.getVarCateImgUrl());
										pbPageViewCateB
												.setVarCateDescrip(catelogTab
														.getVarCateDescrip());
										pbPageViewCateB
												.setIntCateType(catelogTab
														.getIntType());
									}

									// 设置分类中显示的属性值列表
									PbContentAttributeValueList.Builder pbContAVListB = PbContentAttributeValueList
											.newBuilder();
									List<ViewContentAttributeTab> viewContAttrList = viewContentAttributeTabService
											.getViewContentAttributeList(pageView
													.getIntViewId());
									if (viewContAttrList != null
											&& viewContAttrList.size() > 0) {
										for (ViewContentAttributeTab viewConAttri : viewContAttrList) {
											PbContentAttributeValue.Builder pbContAttrValueB = PbContentAttributeValue
													.newBuilder();
											pbContAttrValueB
													.setIntAttriId(viewConAttri
															.getIntAttriId());
											pbContAttrValueB
													.setIntAttriOrder(viewConAttri
															.getIntAttriOrder());

											AttributeTab attributeTab = attributeTabService
													.get(viewConAttri
															.getIntAttriId());
											pbContAttrValueB
													.setVarAttriName(attributeTab
															.getVarAttriName());

											if (viewConAttri.getIntAttriId() == Const.CATELOG_NAME_ATTRIBUTE_ID) {// 如果为分类名称
												pbContAttrValueB
														.setVarAttriValue(catelogTab
																.getVarCateName());
											} else if (viewConAttri
													.getIntAttriId() == Const.CATELOG_IMG_ATTRIBUTE_ID) {// 如果为分类缩略图
												pbContAttrValueB
														.setVarAttriValue(catelogTab
																.getVarCateImgUrl());
											} else if (viewConAttri
													.getIntAttriId() == Const.CATELOG_DESCRIP_ATTRIBUTE_ID) {// 如果为分类简介
												pbContAttrValueB
														.setVarAttriValue(catelogTab
																.getVarCateDescrip());
											} else {
												pbContAttrValueB
														.setVarAttriValue("");
											}
											pbContAVListB
													.addPbContentAttributeValueList(pbContAttrValueB);
										}
									}
									pbPageViewCateB
											.setPbContentAttributeValueList(pbContAVListB);

									// 把分类设置到视图List
									pbViewCateListB
											.addPbPageViewCatelog(pbPageViewCateB);
								}
								// 视图设置到页面中
								pbPageViewB
										.setPbPageViewCatelogList(pbViewCateListB);
							}
						} else if (intViewDataType == Const.VIEW_BIND_CONTENT) {// 视图绑定的数据为内容
							PbAppPageContentList.Builder pbAppPageContentList = PbAppPageContentList
									.newBuilder();
							// 获得视图绑定的内容关系列表
							// =========================================
							Object[] result = mobilePageService
									.pagingGetAppPageContentList(pageView, 1,
											userId);
							if ((Integer) result[0] == 1) {
								// 非公共权限，需登录
								log.info("appId:" + userInfo.getAppId()
										+ "userName:" + userInfo.getUserName()
										+ "userId:" + userInfo.getId() + "未登录");
								pbAppPageSCB.setExeResult(PBRESULT.NEEDLOGIN);
								PbAppPageCatelogSC pbAppPageCatelogSC = pbAppPageSCB
										.build();
								return pbAppPageCatelogSC.toByteArray();
							} else if ((Integer) result[0] == 2) {
								pbPageViewB
										.setIntProductCateId((Integer) result[1]);
								pbPageViewB.setIntDataType(3);
							} else {
								pbAppPageContentList = (PbAppPageContentList.Builder) result[1];
								// 把视图内容添加到页面视图中
								pbPageViewB
										.setPbAppPageContentList(pbAppPageContentList);
								// 设置绑定数据的页码数量
								pageCount = appViewContentRelationTabService
										.returnPageCountByViewId(
												pageView.getIntViewId(), appId,
												userId);
								pbPageViewB.setIntPageNum(pageCount);
							}
							// ==========================================
						} else if (intViewDataType == Const.VIEW_BIND_FUNCTION) {
							// 绑定的功能
							PbMoreContentList.Builder pbMoreContentList = PbMoreContentList
									.newBuilder();
							List<MoreContentTab> moreContList = moreContentTabService
									.getMoreContentListByViewId(appId,
											pageView.getIntViewId(), 1);
							if (moreContList != null && moreContList.size() > 0) {
								for (MoreContentTab more : moreContList) {
									if (more.getIntMoreActionType() == 51) {
										if (!isLogin) {
											log.info("appId:"
													+ userInfo.getAppId()
													+ "userName:"
													+ userInfo.getUserName()
													+ "userId:"
													+ userInfo.getId() + "未登录");
											pbAppPageSCB
													.setExeResult(PBRESULT.NEEDLOGIN);
											PbAppPageCatelogSC pbAppPageCatelogSC = pbAppPageSCB
													.build();
											return pbAppPageCatelogSC
													.toByteArray();
										}
										// 封装个人信息
										more.setVarMoreContent(populateUserInfo(
												user, more.getVarMoreContent()));
									}
									PbMoreContent.Builder pbMoreB = PbMoreContent
											.newBuilder();
									int iconId = more.getIntIconId();
									AppIconTab appIconTab = appIconTabService
											.get(iconId);
									String iconUrl = "";
									if (appIconTab != null) {
										iconUrl = appIconTab.getVarIconUrl();
									}

									pbMoreB.setIntAppId(more.getIntAppId());
									pbMoreB.setIntMoreActionType(more
											.getIntMoreActionType());
									pbMoreB.setIntMoreContentId(more
											.getIntMoreContent());
									pbMoreB.setVarMoreName(more
											.getVarMoreName());
									pbMoreB.setVarMoreContent(more
											.getVarMoreContent());
									pbMoreB.setVarMoreImgUrl(iconUrl);
									pbMoreB.setIntOrder(more.getIntOrder());
									pbMoreContentList
											.addPbMoreContentList(pbMoreB);
								}
								pbPageViewB
										.setPbMoreContentList(pbMoreContentList);
								pbPageViewB.setIntPageNum(1);
							}
						}
						// 把视图加到视图列表中
						pbPageViewList.addPbPageView(pbPageViewB);
						// 把View加到页面上
						pbAppPageB.setPbPageViewList(pbPageViewList);
					}
					pbAppPageSCB.setPbAppPage(pbAppPageB);
					pbAppPageSCB.setExeResult(PBRESULT.SUCCESS);
					log.info(LOG_METHOD_NAME + Const.LOG_DATA_SUCCESS);
				} else {
					log.info(LOG_METHOD_NAME + Const.LOG_DATA_NULL);
					pbAppPageSCB.setExeResult(PBRESULT.NULL);
				}
			} catch (Exception e) {
				log.error(LOG_METHOD_NAME + Const.LOG_DATA_EXCEPTION, e);
				e.printStackTrace();
				pbAppPageSCB.setExeResult(PBRESULT.EXCEPTION);
			}
		} else {
			log.info(LOG_METHOD_NAME + Const.LOG_BYTE_NULL);
			pbAppPageSCB.setExeResult(PBRESULT.FAILED);
		}
		PbAppPageCatelogSC pbAppPageCatelogSC = pbAppPageSCB.build();
		return pbAppPageCatelogSC.toByteArray();
	}

	private boolean checkIfViewNeedLogin(List<AppPageViewTab> appViewList) {
		for (AppPageViewTab pageView : appViewList) {
			if (StringUtils.isBlank(pageView.getVarViewConfig()))
				continue;
			int needLogin = JSONObject.fromObject(pageView.getVarViewConfig())
					.getInt("view_need_login_before");
			if (needLogin == 1)
				return true;
		}
		return false;
	}

	private String populateUserInfo(Users user, String jsonData)
			throws Exception {
		JSONObject result = new JSONObject();
		result.put("avatar", user.getAvatar());
		jsonData = jsonData.substring(1, jsonData.length() - 1);
		JSONArray datas = JSONArray.fromObject(JSONObject.fromObject(jsonData)
				.get("contentAttrInfo"));
		Field field;
		JSONArray attrs = new JSONArray();
		for (Object object : datas) {
			JSONObject data = JSONObject.fromObject(object);
			field = fieldService.get(data.getLong("intAttriId"));
			if (field == null)
				continue;
			data.put("attrType", field.getMetaType());
			data.put("attrName", field.getAliasName() == null ? field.getName()
					: field.getAliasName());
			data.put("intOrder", data.getInt("intOrder"));
			String value = populateUserBasicInfo(user, field);
			if (Const.FILED_TYPE_IMAGERADIO.equals(field.getMetaType())) {
				// 图片选项类型
				value = populateImageOption(field, value);
			}
			data.put("attrValue", value);
			attrs.add(data);
		}
		result.put("datas", attrs);
		return result.toString();
	}

	private String populateImageOption(Field field, String value) {
		JSONObject mask = JSONObject.fromObject(field.getMask());
		JSONArray options = JSONArray.fromObject(mask.get("optionValues"));
		JSONArray optImgs = JSONArray.fromObject(mask.get("optionImageUrls"));
		if (value == null)
			return (String) optImgs.get(0);
		for (int j = 0; j < options.size(); j++) {
			if (value.equals(options.get(j))) {
				value = (String) optImgs.get(j);
				break;
			}
		}
		return value;
	}

	private String populateUserBasicInfo(Users user, Field field)
			throws Exception {
		String name = field.getName();
		if ("用户名".equals(name)) {
			return user.getUserName();
		} else if ("昵称".equals(name)) {
			return user.getUserAilas();
		} else if ("积分".equals(name)) {
			return user.getRankPoint() == null ? "" : user.getRankPoint()
					.toString();
		} else if ("会员等级".equals(name)) {
			return userPointRanksService.getRankNameByPoint(user.getId());
		} else if ("地址".equals(name)) {
			return user.getAddressId() == null ? "" : (addressService.get(user
					.getAddressId()).getAddressLine());
		} else if ("电话号码".equals(name)) {
			return user.getPhoneNumber();
		} else if ("邮箱".equals(name)) {
			return user.getEmail();
		} else if ("性别".equals(name)) {
			return user.getSex();
		} else {
			FieldValues fieldValues = fieldValuesService
					.getValuesByFieldTargetId(field.getId(), user.getId());
			if (fieldValues == null) {
				return "";
			} else {
				return fieldValues.getValueStr();
			}
		}
	}

	/**
	 * 获得显示内容列表的页面信息 PbAppPageContentSC
	 * 
	 * @param bytes
	 * @return
	 * @author 甘建新 2012-7-25下午09:39:19
	 */
	public byte[] getAppContentPage(byte[] bytes) {
		LOG_METHOD_NAME = "getAppContentPage";
		PbAppPageContentSC.Builder pbAppContSCB = PbAppPageContentSC
				.newBuilder();
		PbAppContentPage.Builder pbAppContB = PbAppContentPage.newBuilder();
		if (bytes != null) {
			try {
				PbAppPageContentCS pbAppContCS = PbAppPageContentCS
						.parseFrom(bytes);
				int catelogId = pbAppContCS.getIntCatelogId();
				int pageId = pbAppContCS.getIntPageId();
				int appId = pbAppContCS.getIntAppId();
				String accessTokenValue = pbAppContCS.getAccessTokenValue();

				log.info(LOG_METHOD_NAME + "【appId:" + appId + ",pageId:"
						+ pageId + "】");
				// 校验是否登录 start
				UsersInfoDetails userInfo = tokenService
						.loadUsersInfoDetails(accessTokenValue);
				long userId = 0;
				if (userInfo != null && !"ANON".equals(userInfo.getUserType())) {
					userId = userInfo.getId();
				}
				CatelogTab catelog = catelogTabService.get(catelogId);
				if (catelog.getIntPrivilege() == CatelogTab.PERSON_PRIVILEGE
						&& userId == 0) {
					log.info("appId:" + userInfo.getAppId() + "userName:"
							+ userInfo.getUserName() + "userId:"
							+ userInfo.getId() + "未登录");
					pbAppContSCB.setExeResult(PBRESULT.NEEDLOGIN);
					return pbAppContSCB.build().toByteArray();
				}
				// 校验是否登录 end

				log.info(LOG_METHOD_NAME + "【catelogId:" + catelogId
						+ ",pageId:" + pageId + ",appId:" + appId + "】");
				// 获得页面信息
				AppPageTab appPageTab = appPageTabService.get(pageId);
				if (appPageTab != null) {
					// 定义页面标题信息
					String varTitleName = appPageTab.getVarTitleName();
					AppIconTab titleIcon = null;
					if (appPageTab.getIntTitleIconId() != null
							&& appPageTab.getIntTitleIconId() != 0) {
						titleIcon = appIconTabService.get(appPageTab
								.getIntTitleIconId());
					}
					// AppIconTab backgIcon =
					// appIconTabService.get(appPageTab.getIntTitleBackgId());

					String varTitleIconImg = "";
					// String varTitleBackgImg = "";

					if (titleIcon != null) {
						varTitleIconImg = titleIcon.getVarIconUrl();
					}

					if (varTitleName == null || varTitleName.trim().equals("")) {
						varTitleName = "";
					}
					if (varTitleIconImg == null
							|| varTitleIconImg.trim().equals("")) {
						varTitleIconImg = "";
					}
					pbAppContB.setVarTitleName(varTitleName);
					pbAppContB.setVarTitleIconImg(varTitleIconImg);
				}

				// 通过页面ID，获得页面中包含的视图信息(包含的数据信息列表、显示的属性列表)
				PbAppPageContentView.Builder pbAppPageConVB = PbAppPageContentView
						.newBuilder();
				List<AppPageViewTab> appPageViewList = appPageViewTabService
						.getViewListByPageId(pageId);
				int viewId = 0;
				AppPageViewTab appPageV = null;
				if (appPageViewList != null && appPageViewList.size() == 1) {
					appPageV = appPageViewList.get(0);
					viewId = appPageV.getIntViewId();
					pbAppPageConVB.setIntModuleStyleId(appPageV
							.getIntModuleStyleId());
					pbAppPageConVB
							.setIntResourceId(appPageV.getIntResourceId());
					pbAppPageConVB.setIntViewId(appPageV.getIntViewId());
					pbAppPageConVB.setIntViewOrder(appPageV.getIntViewOrder());

					pbAppPageConVB.setVarViewName(appPageV.getVarViewName());
					pbAppPageConVB
							.setVarViewConfig(appPageV.getVarViewConfig() == null ? ""
									: appPageV.getVarViewConfig());
				}

				// 设置VIEW中绑定内容的页数
				pbAppPageConVB.setIntPageCount(contentTabService
						.getContentListPageCount(catelogId, appId));
				// 设置View中显示内容数据列表
				PbAppPageContentList.Builder pbAppPageContListB = PbAppPageContentList
						.newBuilder();
				// 获得第一页的数据
				SortCondition condition = new SortCondition();
				condition.setIntCateId(catelogId);
				condition.setIntPageNum(1);
				condition.setIntViewId(viewId);
				List<ContentTab> contentTabList = contentTabService
						.getContentListByPage(condition, appId);
				if (contentTabList != null && contentTabList.size() > 0) {
					for (ContentTab contentTab : contentTabList) {
						if (catelog.getIntPrivilege() == CatelogTab.PERSON_PRIVILEGE
								&& contentTab.getIntPrivilegeUser() != userId)
							continue;
						PbAppPageContent.Builder pbAppPageContB = PbAppPageContent
								.newBuilder();
						pbAppPageContB.setIntAppId(contentTab.getIntAppId());
						pbAppPageContB.setIntCateId(contentTab.getIntCateId());
						pbAppPageContB.setIntContentId(contentTab
								.getIntContentId());
						pbAppPageContB.setIntEnterpId(contentTab
								.getIntEnterpId());
						pbAppPageContB.setIntViewCount(contentTab
								.getIntViewCount());
						pbAppPageContB.setVarContentDescrip(contentTab
								.getVarContentDescript());

						pbAppPageContB.setVarContentImgUrl(contentTab
								.getVarContentImgUrl());
						pbAppPageContB.setVarContentName(contentTab
								.getVarContentName());
						// if (appPageV != null &&
						// appPageV.isContainStatusBar()){
						pbAppPageContB.setVarStatisticData(mobilePageService
								.populateContentStatusBar(contentTab
										.getIntContentId()));
						// }

						// 设置内容详情页面访问地址
						String url = "";
						CatelogTab catelogTab = catelogTabService
								.getSuperCatelogByCateId(contentTab
										.getIntCateId());
						int superCatelogId = 0;
						if (catelogTab != null) {
							superCatelogId = catelogTab.getIntCateId();
						}
						AppDetailPageTab appDetailPageTab = appDetailPageTabService
								.getAppDetailInfo(appId, superCatelogId);
						if (appDetailPageTab != null) {
							url = appDetailPageTab.getVarPageUrl()
									+ contentTab.getIntContentId();
						}
						pbAppPageContB.setVarDetailPageUrl(url);
						// 设置页面类型
						pbAppPageContB.setIntDetailPageType(catelogTab.getIntType());

						pbAppPageContB.setDatAddDate(contentTab
								.getDatAddDatetime());

						// 设置内容绑定的属性列表
						// 获得属性键值对
						Map<Integer, String> keyValueMap = attributeValueTabService
								.getAttriIdValueMap(contentTab
										.getIntContentId());
						PbContentAttributeValueList.Builder pbContAttrVListB = PbContentAttributeValueList
								.newBuilder();
						List<ViewContentAttributeTab> viewContAttriList = viewContentAttributeTabService
								.getViewContentAttributeList(pbAppPageConVB
										.getIntViewId());
						if (viewContAttriList != null
								&& viewContAttriList.size() > 0) {
							for (ViewContentAttributeTab viewContentAttributeTab : viewContAttriList) {
								PbContentAttributeValue.Builder pbContAttrValueB = PbContentAttributeValue
										.newBuilder();

								AttributeTab attributeTab = attributeTabService
										.get(viewContentAttributeTab
												.getIntAttriId());
								if (attributeTab != null) {
									pbContAttrValueB
											.setIntAttriId(viewContentAttributeTab
													.getIntAttriId());
									pbContAttrValueB.setIntContentId(contentTab
											.getIntContentId());
									String attrName = attributeTab
											.getVarAttriName();
									pbContAttrValueB
											.setVarAttriName(attrName != null ? attrName
													: "");
									// 添加时间属性处理
									String value;
									if (viewContentAttributeTab.getIntAttriId() == Const.CATELOG_ADDTIME_ATTRIBUTE_ID) {
										value = contentTab.getAddTimeFormat();
									} else {
										value = keyValueMap
												.get(viewContentAttributeTab
														.getIntAttriId());
									}
									if (value == null) {
										value = "";
									}
									pbContAttrValueB.setVarAttriValue(value);
									pbContAttrValueB
											.setIntAttriOrder(viewContentAttributeTab
													.getIntAttriOrder());
									pbContAttrValueB.setIntAttriValueId(0);
								}

								pbContAttrVListB
										.addPbContentAttributeValueList(pbContAttrValueB);
							}
						}
						pbAppPageContB
								.setPbContentAttributeValueList(pbContAttrVListB);
						pbAppPageContListB.addPbAppPageContent(pbAppPageContB);
					}
				}
				pbAppPageConVB.setPbAppPageContentList(pbAppPageContListB);

				pbAppContB.setPbAppPageContentView(pbAppPageConVB);
				// =======================================================================
				// 设置VIEW到页面中
				pbAppContSCB.setPbAppContentPage(pbAppContB);
				pbAppContSCB.setExeResult(PBRESULT.SUCCESS);
				log.info(LOG_METHOD_NAME + Const.LOG_DATA_SUCCESS);
			} catch (Exception e) {
				log.error(LOG_METHOD_NAME + Const.LOG_DATA_EXCEPTION, e);
				e.printStackTrace();
				pbAppContSCB.setExeResult(PBRESULT.EXCEPTION);
			}
		} else {
			log.info(LOG_METHOD_NAME + Const.LOG_BYTE_NULL);
			pbAppContSCB.setExeResult(PBRESULT.FAILED);
		}
		return pbAppContSCB.build().toByteArray();
	}

	/**
	 * 获得应用的页面结构 GET_APP_PAGES
	 * 
	 * @param appPageCS
	 * @return
	 * @author 甘建新 2012-7-11下午11:11:08
	 */

	/**
	 * public byte[] getAppPages(byte[] bytes){ PbAppPageList.Builder
	 * pbAppPageListBuilder = PbAppPageList.newBuilder(); PbAppPageSC.Builder
	 * pbAppPageSCBuilder = PbAppPageSC.newBuilder();
	 * 
	 * if (bytes!=null) { try { PbAppPageCS pbAppPageCS =
	 * PbAppPageCS.parseFrom(bytes); int appId = pbAppPageCS.getIntAppId(); int
	 * pageId = pbAppPageCS.getIntResourceId(); if (pageId>=0)
	 * {//PageId为0，表示是顶级的Page页面 List<AppPageTab> pageList =
	 * appPageTabService.getPagesListByParentId(appId, pageId); if
	 * (pageList!=null && pageList.size()>0) { for (AppPageTab appPageTab :
	 * pageList) { PbAppPage.Builder pbAppPageBuilder = PbAppPage.newBuilder();
	 * pbAppPageBuilder.setIntAppId(appPageTab.getIntAppId());
	 * pbAppPageBuilder.setIntContentId(appPageTab.getIntContentId());
	 * pbAppPageBuilder.setIntContentType(appPageTab.getIntResourceType());
	 * pbAppPageBuilder.setIntEnterpId(appPageTab.getIntEnterpId());
	 * pbAppPageBuilder.setIntOrder(appPageTab.getIntOrder());
	 * pbAppPageBuilder.setIntPageId(appPageTab.getIntResourceId());
	 * pbAppPageBuilder.setIntParentPageId(appPageTab.getIntParentResourceId());
	 * pbAppPageBuilder.setIntThisModuleId(appPageTab.getIntThisModuleId());
	 * pbAppPageBuilder.setVarPageName(appPageTab.getVarResourceName());
	 * pbAppPageBuilder.setIntHasSubPage(appPageTab.getIntHasSubPage());
	 * 
	 * //获得页面的标题 PageTitleTab pageTitleTab =
	 * pageTitleTabService.getPageTitleByPageId(appPageTab.getIntResourceId());
	 * if (pageTitleTab!=null) { PbAppPageTitle.Builder pbAppPageTitleBuilder =
	 * PbAppPageTitle.newBuilder();
	 * pbAppPageTitleBuilder.setIntTitleId(pageTitleTab.getIntTitleId());
	 * pbAppPageTitleBuilder.setVarTitleName(pageTitleTab.getVarTitleName());
	 * pbAppPageBuilder.setPbAppPageTitle(pbAppPageTitleBuilder); }
	 * 
	 * //获得页面显示属性列表 List<PageAttributeTab> pageAttributeList =
	 * pageAttributeTabService
	 * .getAttributeListOnPage(appPageTab.getIntResourceId()); if
	 * (pageAttributeList!=null && pageAttributeList.size()>0) {
	 * PbAppPageAttributeList.Builder pbAppPageAttributeListBuilder =
	 * PbAppPageAttributeList.newBuilder(); for (PageAttributeTab
	 * pageAttributeTab : pageAttributeList) { PbAppPageAttribute.Builder
	 * pbAppPageAttributeBuilder = PbAppPageAttribute.newBuilder();
	 * pbAppPageAttributeBuilder
	 * .setIntAttriId(pageAttributeTab.getIntAttriId());
	 * pbAppPageAttributeBuilder.setIntOrder(pageAttributeTab.getIntOrder());
	 * pbAppPageAttributeBuilder
	 * .setIntPageAttributeId(pageAttributeTab.getIntPageAttributeId());
	 * pbAppPageAttributeBuilder.setIntPageId(appPageTab.getIntResourceId());
	 * 
	 * pbAppPageAttributeListBuilder.addPbAppPageAttribute(
	 * pbAppPageAttributeBuilder); }
	 * 
	 * //获得页面中显示的分类信息 CatelogTab catelog =
	 * catelogTabService.get(appPageTab.getIntContentId());
	 * PbContentCatelog.Builder pbCate = PbContentCatelog.newBuilder(); if
	 * (catelog!=null) { pbCate.setIntAppId(catelog.getIntAppId());
	 * pbCate.setIntCateId(catelog.getIntCateId());
	 * pbCate.setIntEnterpId(catelog.getIntEnterpId());
	 * pbCate.setIntParentCateId(catelog.getIntParentCateId());
	 * 
	 * pbCate.setVarCateImgUrl(catelog.getVarCateImgUrl());
	 * pbCate.setVarCateName(catelog.getVarCateName());
	 * 
	 * //设置分类的属性列表 PbCatelogAttributeList.Builder pbCateAList =
	 * PbCatelogAttributeList.newBuilder(); List<AttributeTab> attrList =
	 * attributeTabService.getAttributeListByCatelogId(catelog.getIntCateId());
	 * if (attrList!=null && attrList.size()>0) { for (AttributeTab attr :
	 * attrList) { PbCatelogAttribute.Builder pbCateAttrB =
	 * PbCatelogAttribute.newBuilder();
	 * pbCateAttrB.setIntAttrId(attr.getIntAttriId());
	 * pbCateAttrB.setIntCateId(attr.getIntCateId());
	 * pbCateAttrB.setVarAttriName(attr.getVarAttriName());
	 * 
	 * pbCateAList.addPbCatelogAttribute(pbCateAttrB); } }
	 * pbCate.setPbCatelogAttributeList(pbCateAList); } //把分类加到应用页面上
	 * pbAppPageBuilder.setPbContentCatelog(pbCate);
	 * 
	 * pbAppPageBuilder.setPbAppPageAttribute(pbAppPageAttributeListBuilder); }
	 * //将数据设置到List中 pbAppPageListBuilder.addPbAppPageList(pbAppPageBuilder); }
	 * //将页面List设置到返回数据的PB对象中
	 * pbAppPageSCBuilder.setPbAppPageList(pbAppPageListBuilder); //设置数据成功消息
	 * pbAppPageSCBuilder.setExeResult(PBRESULT.SUCCESS); }else { //设置数据获取失败消息
	 * pbAppPageSCBuilder.setPbAppPageList(pbAppPageListBuilder);
	 * pbAppPageSCBuilder.setExeResult(PBRESULT.NULL); } } } catch (Exception e)
	 * { //设置数据获取异常消息 log.info(LOG_METHOD_NAME+"数据异常："); e.printStackTrace();
	 * pbAppPageSCBuilder.setPbAppPageList(pbAppPageListBuilder);
	 * pbAppPageSCBuilder.setExeResult(PBRESULT.EXCEPTION); } }else {
	 * pbAppPageSCBuilder.setPbAppPageList(pbAppPageListBuilder);
	 * pbAppPageSCBuilder.setExeResult(PBRESULT.FAILED); } return
	 * pbAppPageSCBuilder.build().toByteArray(); }
	 **/
	/**
	 * 获得应用模板样式 GET_APP_MODULE_STYLE
	 * 
	 * @param appModuleStyleCS
	 * @return
	 * @author 甘建新 2012-7-11下午11:13:22
	 */
	/**
	 * public byte[] getAppModuleStyle(byte[] bytes){ PbAppModuleStyleSC.Builder
	 * pbAppModuleStyleSCBuilder = PbAppModuleStyleSC.newBuilder();
	 * PbAppModuleStyle.Builder pbAppModuleStyleBuilder =
	 * PbAppModuleStyle.newBuilder(); if (bytes!=null && bytes.length>0) { try {
	 * //将字节数组转换成PB对象 PbAppModuleStyleCS pbAppModuleStyleCS =
	 * PbAppModuleStyleCS.parseFrom(bytes); //根据模板ID，从数据库中取出模板的相关信息
	 * ModuleStyleTab moduleStyleTab =
	 * moduleStyleTabService.get(pbAppModuleStyleCS.getIntModuleStyleId()); if
	 * (moduleStyleTab!=null) {
	 * pbAppModuleStyleBuilder.setIntModuleStyleId(moduleStyleTab
	 * .getIntModuleStyleId());
	 * pbAppModuleStyleBuilder.setIntTypeId(moduleStyleTab.getIntTypeId());
	 * pbAppModuleStyleBuilder
	 * .setVarModuleImgUrl(moduleStyleTab.getVarModuleImgUrl());
	 * pbAppModuleStyleBuilder
	 * .setVarModuleStyleName(moduleStyleTab.getVarModuleStyleName());
	 * 
	 * //将PB数据的对象到需要目的对象
	 * pbAppModuleStyleSCBuilder.setPbAppModuleStyle(pbAppModuleStyleBuilder);
	 * //设置数据获取结果 pbAppModuleStyleSCBuilder.setExeResult(PBRESULT.SUCCESS);
	 * }else {
	 * pbAppModuleStyleSCBuilder.setPbAppModuleStyle(pbAppModuleStyleBuilder);
	 * pbAppModuleStyleSCBuilder.setExeResult(PBRESULT.NULL); } } catch
	 * (Exception e) { //产生异常 log.info(LOG_METHOD_NAME+"数据操作异常：");
	 * e.printStackTrace();
	 * pbAppModuleStyleSCBuilder.setPbAppModuleStyle(pbAppModuleStyleBuilder);
	 * pbAppModuleStyleSCBuilder.setExeResult(PBRESULT.EXCEPTION); } }else {
	 * pbAppModuleStyleSCBuilder.setPbAppModuleStyle(pbAppModuleStyleBuilder);
	 * pbAppModuleStyleSCBuilder.setExeResult(PBRESULT.FAILED); } return
	 * pbAppModuleStyleSCBuilder.build().toByteArray(); }
	 **/
	/**
	 * 获得应用的样式 GET_APP_STYLE
	 * 
	 * @param appStyleCS
	 * @return
	 * @author 甘建新 2012-7-11下午11:14:38
	 */
	/**
	 * public byte[] getAppStyle(byte[] bytes){ PbAppStyleSC.Builder
	 * pbAppStyleSCBuilder = PbAppStyleSC.newBuilder(); PbAppStyle.Builder
	 * pbAppStyleBuilder = PbAppStyle.newBuilder(); if (bytes!=null &&
	 * bytes.length>0) { try { //转换携带的参数 PbAppStyleCS pbAppStyleCS =
	 * PbAppStyleCS.parseFrom(bytes); int styleId = pbAppStyleCS.getStyleId();
	 * //获得数据 AppStyleTab appStyleTab = appStyleTabService.get(styleId); if
	 * (appStyleTab!=null) {
	 * pbAppStyleBuilder.setStyleId(appStyleTab.getIntAppStyleId());
	 * pbAppStyleBuilder.setStyleImgUrl(appStyleTab.getVarAppStyleUrl());
	 * pbAppStyleBuilder.setStyleName(appStyleTab.getVarAppStyleName());
	 * 
	 * //将PB对象设置到返回对象中 pbAppStyleSCBuilder.setPbAppStyle(pbAppStyleBuilder);
	 * //设置数据获取状态 pbAppStyleSCBuilder.setExeResult(PBRESULT.SUCCESS); }else {
	 * pbAppStyleSCBuilder.setPbAppStyle(pbAppStyleBuilder);
	 * pbAppStyleSCBuilder.setExeResult(PBRESULT.NULL); } } catch (Exception e)
	 * { e.printStackTrace();
	 * pbAppStyleSCBuilder.setPbAppStyle(pbAppStyleBuilder);
	 * pbAppStyleSCBuilder.setExeResult(PBRESULT.EXCEPTION); } }else {
	 * pbAppStyleSCBuilder.setPbAppStyle(pbAppStyleBuilder);
	 * pbAppStyleSCBuilder.setExeResult(PBRESULT.FAILED); } //将样式转换成字节数组 return
	 * pbAppStyleSCBuilder.build().toByteArray(); }
	 **/
	/**
	 * 获得应用页面上显示的属性列表信息 GET_APP_PAGE_ATTRIBUTE
	 * 
	 * @param appPageAttributeListCS
	 * @return
	 * @author 甘建新 2012-7-11下午11:16:21
	 */
	/**
	 * public byte[] getAppPageAttribute(byte[] bytes){
	 * PbAppPageAttributeListSC.Builder pbAppPageAttributeListSCBuilder =
	 * PbAppPageAttributeListSC.newBuilder(); PbAppPageAttributeList.Builder
	 * pbAppPageAttributeListBuilder = PbAppPageAttributeList.newBuilder(); if
	 * (bytes!=null) { try { PbAppPageAttributeListCS pbAppPageAttributeListCS =
	 * PbAppPageAttributeListCS.parseFrom(bytes); int pageId =
	 * pbAppPageAttributeListCS.getIntResourceId(); //获得页面显示的属性关联表信息列表
	 * List<PageAttributeTab> pageAttributeList =
	 * pageAttributeTabService.getAttributeListOnPage(pageId); if
	 * (pageAttributeList!=null && pageAttributeList.size()>0) { for
	 * (PageAttributeTab pageAttributeTab : pageAttributeList) {
	 * PbAppPageAttribute.Builder pbAppPageAttributeBuilder =
	 * PbAppPageAttribute.newBuilder();
	 * pbAppPageAttributeBuilder.setIntAttriId(pageAttributeTab
	 * .getIntAttriId());
	 * pbAppPageAttributeBuilder.setIntOrder(pageAttributeTab.getIntOrder());
	 * pbAppPageAttributeBuilder
	 * .setIntPageAttributeId(pageAttributeTab.getIntPageAttributeId());
	 * pbAppPageAttributeBuilder
	 * .setIntPageId(pageAttributeTab.getIntResourceId());
	 * 
	 * pbAppPageAttributeListBuilder.addPbAppPageAttribute(
	 * pbAppPageAttributeBuilder); } //设置返回数据
	 * pbAppPageAttributeListSCBuilder.setPbAppPageAttributeList
	 * (pbAppPageAttributeListBuilder);
	 * pbAppPageAttributeListSCBuilder.setExeResult(PBRESULT.SUCCESS); }else {
	 * //获取数据为空 pbAppPageAttributeListSCBuilder.setPbAppPageAttributeList(
	 * pbAppPageAttributeListBuilder);
	 * pbAppPageAttributeListSCBuilder.setExeResult(PBRESULT.NULL); } } catch
	 * (Exception e) {//获取数据异常 e.printStackTrace();
	 * pbAppPageAttributeListSCBuilder
	 * .setPbAppPageAttributeList(pbAppPageAttributeListBuilder);
	 * pbAppPageAttributeListSCBuilder.setExeResult(PBRESULT.EXCEPTION); } }else
	 * {//获取数据其他异常 pbAppPageAttributeListSCBuilder.setPbAppPageAttributeList(
	 * pbAppPageAttributeListBuilder);
	 * pbAppPageAttributeListSCBuilder.setExeResult(PBRESULT.FAILED); } return
	 * pbAppPageAttributeListSCBuilder.build().toByteArray(); }
	 **/

	// Setter
	public void setAppTabService(AppTabService appTabService) {
		this.appTabService = appTabService;
	}

	public void setAppUpdateTabService(AppUpdateTabService appUpdateTabService) {
		this.appUpdateTabService = appUpdateTabService;
	}

	public void setAppPageTabService(AppPageTabService appPageTabService) {
		this.appPageTabService = appPageTabService;
	}

	public void setCatelogTabService(CatelogTabService catelogTabService) {
		this.catelogTabService = catelogTabService;
	}

	public void setAttributeTabService(AttributeTabService attributeTabService) {
		this.attributeTabService = attributeTabService;
	}

	public void setAppPageViewTabService(
			AppPageViewTabService appPageViewTabService) {
		this.appPageViewTabService = appPageViewTabService;
	}

	public void setAppViewCatelogRalationTabService(
			AppViewCatelogRalationTabService appViewCatelogRalationTabService) {
		this.appViewCatelogRalationTabService = appViewCatelogRalationTabService;
	}

	public void setAppIconTabService(AppIconTabService appIconTabService) {
		this.appIconTabService = appIconTabService;
	}

	public void setContentTabService(ContentTabService contentTabService) {
		this.contentTabService = contentTabService;
	}

	public void setViewContentAttributeTabService(
			ViewContentAttributeTabService viewContentAttributeTabService) {
		this.viewContentAttributeTabService = viewContentAttributeTabService;
	}

	public void setAttributeValueTabService(
			AttributeValueTabService attributeValueTabService) {
		this.attributeValueTabService = attributeValueTabService;
	}

	public void setAppDetailPageTabService(
			AppDetailPageTabService appDetailPageTabService) {
		this.appDetailPageTabService = appDetailPageTabService;
	}

	public void setAppViewContentRelationTabService(
			AppViewContentRelationTabService appViewContentRelationTabService) {
		this.appViewContentRelationTabService = appViewContentRelationTabService;
	}

	public void setBindContentAttributeTabService(
			BindContentAttributeTabService bindContentAttributeTabService) {
		this.bindContentAttributeTabService = bindContentAttributeTabService;
	}

	public void setMobilePageService(MobilePageService mobilePageService) {
		this.mobilePageService = mobilePageService;
	}

	public void setTokenService(TokenService tokenService) {
		this.tokenService = tokenService;
	}

	public void setMoreContentTabService(
			MoreContentTabService moreContentTabService) {
		this.moreContentTabService = moreContentTabService;
	}

	public void setUsersService(UsersService usersService) {
		this.usersService = usersService;
	}

	public void setFieldService(FieldService fieldService) {
		this.fieldService = fieldService;
	}

	public void setFieldValuesService(FieldValuesService fieldValuesService) {
		this.fieldValuesService = fieldValuesService;
	}

	public void setAddressService(AddressService addressService) {
		this.addressService = addressService;
	}

	public void setUserPointRanksService(
			UserPointRanksService userPointRanksService) {
		this.userPointRanksService = userPointRanksService;
	}
}
